﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Input;

using NetExp.MediaXenter.Database;

namespace NetExp.MediaXenter.Utilities
{
    public class KeyboardManager
    {
        private Key exit;
        public Key Exit
        {
            get
            {
                return exit;
            }
            
        }

        private Key back;
        public Key Back
        {
            get
            {
                return back;
            }

        }

        private Key selected;
        public Key Selected
        {
            get
            {
                return selected;
            }

        }

        private Key moveUp;
        public Key MoveUp
        {
            get
            {
                return moveUp;
            }
        }

        private Key moveDown;
        public Key MoveDown
        {
            get
            {
                return moveDown;
            }
        }


        private Key moveLeft;
        public Key MoveLeft
        {
            get
            {
                return moveLeft;
            }
        }


        private Key moveRight;
        public Key MoveRight
        {
            get
            {
                return moveRight;
            }
        }
        
        public KeyboardManager(KeyboardDS keyboardDS)
        {

            exit = GetKey(keyboardDS,"Exit");
            moveDown = GetKey(keyboardDS,"MoveDown");
            moveUp = GetKey(keyboardDS, "MoveUp");
            moveLeft = GetKey(keyboardDS, "MoveLeft");
            moveRight = GetKey(keyboardDS, "MoveRight");
            selected = GetKey(keyboardDS, "Selected");
            back = GetKey(keyboardDS, "Back");
        }

        private Key GetKey(KeyboardDS keyboardDS, string nomeFunzione)
        {
            Key elemento = new Key();
            KeyboardDS.FunctionsRow funzione = (KeyboardDS.FunctionsRow)keyboardDS.Functions.Select("Name='" + nomeFunzione + "'")[0];
            KeyboardDS.KeysRow chiave = (KeyboardDS.KeysRow)keyboardDS.Keys.Select("IdFunction=" + funzione.Id.ToString())[0];

            KeyConverter conv = new KeyConverter();
            elemento = (Key)conv.ConvertFromInvariantString(chiave.Key);
            return elemento;
        }

    }
}
